package com.neusoft.neuiotms.dcom.converter.incident;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.neusoft.bizcore.web.dto.AbstractConverter;
import com.neusoft.neuiotms.dcom.dto.incident.IncidentAppointDTO;
import com.neusoft.neuiotms.dcom.model.incident.IncidentAppoint;
import com.neusoft.neuiotms.dcom.repository.incident.IncidentAppointRepository;

/**
 * @author WYS
 * @date 2020年8月18日 下午2:02:51
 */
@Component
public class IncidentAppointConverter extends AbstractConverter<IncidentAppoint, IncidentAppointDTO> {

    @Autowired
    private IncidentAppointRepository incidentAppointRepository;

    @Override
    public IncidentAppoint toModel(final IncidentAppointDTO dto) {
        IncidentAppoint model;
        if (dto.isNew()) {
            model = new IncidentAppoint();
            model.setCreateTime(new Date());
        } else {
            model = this.incidentAppointRepository.getOne(dto.getId());
            model.setUpdateTime(new Date());
        }
        model.setTaskId(dto.getTaskId());
        model.setWorkNum(dto.getWorkOrderNum());
        model.setAppointUserCode(dto.getAppointUserCode());
        model.setAppointUserName(dto.getAppointUserName());
        model.setExecuteUserCode(dto.getExecuteUserCode());
        model.setExecuteUserName(dto.getExecuteUserName());

        return model;
    }

    @Override
    public IncidentAppointDTO toDTO(final IncidentAppoint model, final boolean forListView) {
        final IncidentAppointDTO dto = new IncidentAppointDTO();
        dto.setId(model.getId());
        dto.setTaskId(model.getTaskId());
        dto.setWorkOrderNum(model.getWorkNum());
        dto.setAppointUserCode(model.getAppointUserCode());
        dto.setAppointUserName(model.getAppointUserName());
        dto.setExecuteUserCode(model.getExecuteUserCode());
        dto.setExecuteUserName(model.getExecuteUserName());

        dto.setCreateTime(model.getCreateTime());
        dto.setUpdateTime(model.getUpdateTime());

        return dto;
    }

}
